Skip to content

Purge page caches after every write; report it in the result (0.1.18) - #12

Merged
mostafasoufi merged 1 commit into
mainfrom
purge-after-writes
Oct 1, 2026
Merged

mostafasoufi merged 1 commit into
mainfrom
purge-after-writes

Conversation

@mostafasoufi

Copy link
Copy Markdown
Member

Fixes #11

What changes

  • After every write and undo, the plugin asks the active page caches to drop what changed:
    • SEO title, description, canonical, noindex and the opening paragraph: the post's URL, plus the home page when the post is the static front page.
    • Alt text: the post the image belongs to (the change's post_id, else the post it was uploaded to).
    • Redirects: the source URL (and that post's purge when the source is a post).
    • llms.txt and AI crawler rules: /llms.txt or /robots.txt, as before.
  • New caches, each through its public API and only when active (all guarded, all wrapped in try/catch, never fatal):
Cache Call (verified in its source)
WP-Optimize 4.7.0 WPO_Page_Cache::instance()->is_enabled(), then WPO_Page_Cache::delete_cache_by_url( $url ) (false = failed)
Nginx Helper 2.4.1 global $nginx_purger → purge_url( $url, false ), only when $nginx_helper_admin->options['enable_purge']
Breeze 2.6.0 do_action( 'purge_post_cache', $post_id ) (its documented call), posts only
Kinsta $kinsta_cache->kinsta_cache_purge->initiate_purge( $post_id, 'post' ); purge_complete_caches() for llms/robots
WP Engine WpeCommon::purge_varnish_cache( $post_id ); purge_varnish_cache() for llms/robots
Pantheon Advanced Page Cache pantheon_wp_clear_edge_paths( $paths )

Existing: WP Rocket (now rocket_clean_home() for the home page, since purging its folder by URL would empty the whole cache), LiteSpeed, W3 Total Cache, WP Super Cache, SiteGround.

  • Kinsta and WP Engine have no one-URL purge, so they purge everything only for the site-wide files; a redirect source that is not a post is left alone there. Kinsta's must-use plugin is not public; its calls are the ones WP Rocket's own Kinsta integration uses. WP Engine's signature was checked in a copy of its must-use plugin.
  • Cloudflare (official plugin 4.14.4): still skipped. It has no public function or action to purge a URL. Its purge method lives on an object it does not expose, and its cloudflare_purge_url_actions filter is read when Cloudflare loads, which is before MonoRanks (plugins load alphabetically). The opening-paragraph write saves the post, so Cloudflare's own transition_post_status hook already purges in that case.

Result field

Each successful write result has cache: { purged: string[], failed: string[], none: bool }. All other fields are unchanged; refused changes carry no cache. Documented in docs/api.md.

New filter monoranks_purge_urls and action monoranks_purged_cache; CachePurger::purge_file() keeps its old return value.

Tests

Unit tests (Brain Monkey) for every adapter: active and inactive, failure, throw, home page, front page, redirect-to-post, plus a Writer test for the cache field. No WP-Optimize integration test (optional; it would need the plugin and its advanced-cache setup in the CI WordPress).

Version 0.1.18 (header, constant, Stable tag, CHANGELOG, readme changelog). Not released.

After each write and undo the plugin asks the active page caches to drop
the page that changed: the post (plus the home page for the static front
page) for SEO fields, alt text and the opening paragraph, the source URL
for redirects, and /llms.txt or /robots.txt as before.

Adds WP-Optimize, Nginx Helper, Breeze, Kinsta, WP Engine and Pantheon
next to WP Rocket, LiteSpeed, W3 Total Cache, WP Super Cache and
SiteGround. Every call is guarded and wrapped so a cache never breaks a
write. Each successful write result now carries
cache: { purged, failed, none }.

Fixes #11
@mostafasoufi
mostafasoufi merged commit 9b7fa8a into main Oct 1, 2026
11 checks passed
@mostafasoufi
mostafasoufi deleted the purge-after-writes branch October 1, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Purge the page cache after a write (WP-Optimize served the old title)

1 participant